<template>
  <div>
    <h1>权益添加</h1>
    <table class="table table-bordered">
      <tbody>
      <tr>
        <td>等级名称</td>
        <td><input type="text" v-model="info.LevelName"/></td>
      </tr>
      <tr>
        <td>等级权益</td>
        <td>
          <span v-for="i in data1.list" :key="i.Id">
            <input :value="i.ReighName" type="checkbox" v-model="info.ReighName"/>{{i.ReighName}}
          </span>
        </td>
      </tr>
      <tr>
        <td>等级状态</td>
        <td>
          <input type="radio" name="state" v-model="info.LevelState" :value="1"/>启用
          <input type="radio" name="state" v-model="info.LevelState" :value="0"/>禁用
        </td>
      </tr>
      <tr>
        <td></td>
        <td>
          <input type="button" value="提交" class="btn btn-success" @click="Ok"/>
        </td>
      </tr>
      </tbody>
    </table>
  </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted} from 'vue'
import axios from "axios";
import moment from "moment";
import {useRoute,useRouter} from "vue-router";

const router = useRouter()
const route = useRoute()


//发送数据
let info:any=reactive({
  "LevelName": "",
  "ReighName": [],
  "LevelState": 1,
})

const Ok=()=>{
  info.ReighName=info.ReighName.toString();
  axios({
    url:"https://localhost:7032/api/User/AddLevel",
    method:"post",
    data:info
  }).then(res=>{
    console.log(res)
    if(res.data==-1)
    {
      alert("权益名称重复")
      return;
    }
    if(res.data>0)
    {
      alert("添加成功")
    router.push("/lebelList")
      return;
    }
    else
    {
      alert("添加失败")
    }
  })
}

onMounted(() => {
  getlist1();
})

//接受数据
let data1:any=reactive({
  list:[]
})
const getlist1=()=>{
  axios({
    url:"https://localhost:7032/api/User/GetRight",
    method:"get",
  }).then(res=>{
    console.log(res)
    data1.list=res.data
  })
}
</script>

<style scoped>

</style>